﻿<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<div id="createDialog" class="container-fluid">
    <div class="row">
        <form id="createForm" method="post" class="form-horizontal" action="">
        <div class="form-group">
            <label class="col-sm-4 control-label" for="mchid">
                <span class="help-inline"><font color="red">*</font> </span>
                商户编号</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="mchid" name="mchid" maxlength="30" placeholder="商户编号" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label" for="name">
                <span class="help-inline"><font color="red">*</font> </span>
                商户名称</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="name" name="name" maxlength="100" placeholder="商户名称" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label" for="reqkey">
                <span class="help-inline"><font color="red">*</font> </span>
                请求私钥</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="reqkey" name="reqkey" maxlength="128" placeholder="请求私钥" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label" for="reskey">
                <span class="help-inline"><font color="red">*</font> </span>
                响应私钥</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="reskey" name="reskey" maxlength="128" placeholder="响应私钥" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label" for="type">
                <span class="help-inline"><font color="red">*</font> </span>
                商户类型：</label>
            <div class="col-sm-5">
                <select id="type" name="type" class="form-control">
                    <c:forEach var="upmsDict" items="${agentTypeList}">
                        <option value="${upmsDict.dicValue}">${upmsDict.dicText}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label" for="state">
                <span class="help-inline"><font color="red">*</font> </span>
                商户状态：</label>
            <div class="col-sm-5">
                <select id="state" name="state" class="form-control">
                    <option value="1" <c:if test="${umbrellaRuleDeposit.status==1}">selected="selected"</c:if>>启用</option>
                    <option value="0" <c:if test="${umbrellaRuleDeposit.status==0}">selected="selected"</c:if>>>禁止</option>
                </select>
            </div>
        </div>
            <div class="form-group">
	        <div class="col-sm-9 col-sm-offset-4">
	            <button type="button" class="btn btn-primary" onclick="createSubmit();">
	                保存
	            </button>
	            <button type="button" class="btn btn-default"
	                    onclick="createDialog.close();">取消
	            </button>
	        </div>
            </div>
	</form>
</div>
<script>
function createSubmit() {
    $.ajax({dataType: 'json',
        type: 'post',
        url: '${basePath}/manage/mchinfo/create',
        data: $('#createForm').serialize(),
        beforeSend: function() {
            if ($('#mchid').val() == '') {
                $('#mchid').focus();
                return false;
            }
            if ($('#name').val() == '') {
                $('#name').focus();
                return false;
            }
            if ($('#reqkey').val() == '') {
                $('#reqkey').focus();
                return false;
            }
            if ($('#reskey').val() == '') {
                $('#reskey').focus();
                return false;
            }
        },
        success: function(result) {
			if (result.code != 1) {
				if (result.data instanceof Array) {
					$.each(result.data, function(index, value) {
						$.confirm({
							theme: 'dark',
							animation: 'rotateX',
							closeAnimation: 'rotateX',
							title: false,
							content: value.errorMsg,
							buttons: {
								confirm: {
									text: '确认',
									btnClass: 'waves-effect waves-button waves-light'
								}
							}
						});
					});
				} else {
						$.confirm({
							theme: 'dark',
							animation: 'rotateX',
							closeAnimation: 'rotateX',
							title: false,
							content: result.data,
							buttons: {
								confirm: {
									text: '确认',
									btnClass: 'waves-effect waves-button waves-light'
								}
							}
						});
				}
			} else {
				createDialog.close();
				$table.bootstrapTable('refresh');
			}
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
			$.confirm({
				theme: 'dark',
				animation: 'rotateX',
				closeAnimation: 'rotateX',
				title: false,
				content: textStatus,
				buttons: {
					confirm: {
						text: '确认',
						btnClass: 'waves-effect waves-button waves-light'
					}
				}
			});
        }
    });
}
</script>